#include "WorldTransformation.h"

WorldTransform::WorldTransform() {
	Reset();
}

void WorldTransform::Reset() {
	D3DXMatrixIdentity(&m_translate);
	D3DXMatrixIdentity(&m_rotate);
	D3DXMatrixIdentity(&m_scale);
	D3DXMatrixIdentity(&m_transform);
	m_position = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	m_rotationX = m_rotationY = m_rotationZ = 0.0f;
}

void WorldTransform::translateAbs(float x, float y, float z) {
	m_translate._41 = x;
	m_translate._42 = y;
	m_translate._43 = z;
	m_position.x = x;
	m_position.y = y;
	m_position.z = z;
}

void WorldTransform::translateRel(float x, float y, float z) {
	m_translate._41 += x;
	m_translate._42 += y;
	m_translate._43 += z;
	m_position.x += x;
	m_position.y += y;
	m_position.z += z;
}

void WorldTransform::rotateAbs(float x, float y, float z) {
	m_rotationX = x;
	m_rotationY = y;
	m_rotationZ = z;
	D3DXMatrixRotationYawPitchRoll(&m_rotate, y, x, z);
}

void WorldTransform::rotateRel(float x, float y, float z) {
	m_rotationX += x;
	m_rotationY += y;
	m_rotationZ += z;
	D3DXMatrixRotationYawPitchRoll(&m_rotate, m_rotationY, m_rotationX, m_rotationZ);
}

void WorldTransform::scaleAbs(float x, float y, float z) {
	m_scale._11 = x;
	m_scale._22 = y;
	m_scale._33 = z;
}

void WorldTransform::scaleRel(float x, float y, float z) {
	m_scale._11 += x;
	m_scale._22 += y;
	m_scale._33 += z;
}

D3DXMATRIX* WorldTransform::getTransform() {
	m_transform = m_scale * m_rotate * m_translate; 
	return &m_transform;
}
